package contact.importEmailContact;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.dom4j.Document;
import org.dom4j.io.SAXReader;

public class Hotmail {
	public static void main(String[] args) throws Exception {
		new Hotmail().getDataInput();
	}

	public void getDataInput() {

		try {
			String locationId = "15f765cb62a58506";
			String delegationToken = "EwCoARAnAAAUWkziSC7RbDJKS1VkhugDegv7L0eAAO6CW1T6hDnKG0smJf52oZdWBRZtTfpGNz0CH1QqNP1dEx%2BXTRUfH06yeZK2h72EHrsaxH2%2FNzw13xlzGkvIo%2FchM5cRO%2FsWF2OLGRjDMGX%2BAfsQa%2FP2dHQfYHJ849kLXIpVEoosPeQrRdfiGiSBiwDHho%2F0Yhgc6tDjarwOlYNuA2YAAAiSnrizVtSTo%2FgAH4iOvDZ1B4HEgnfiK4NhiOnvbHzmZ0fztYs9FgMFt8fuUpKuE5yzPcorJmbbdycQX4%2FOyW%2Bn714WovDyer12W%2FV81V6eev36TUQWmbAWHEIL8egViOHosUpxglgBErwDW8CpYZIWmKLTFBFARbxgOGecGPwP%2F5TGu3%2FATfRmLsp8VxJH%2FJyJpRWo2P0AFt7dBkXqT4AAPOPVLZ0Ly6Bixtqj72hk%2FW9lHsjmQN770U0cFZP2uJpXI3tFQkLPytDF07GaDVJaFyex3Tl2qwBSvC9331wFQ0zMekGqmjS1wviB7eqODBL5UnwF%2FKEcAf5lN1r4jlhWkzAAAA%3D%3D";
			URL u = new URL("https://livecontacts.services.live.com/users/@L@"
					+ locationId + "/rest/LiveContacts");
			HttpURLConnection urlConnection = (HttpURLConnection) u
					.openConnection();
			urlConnection.setRequestMethod("GET");
			urlConnection.setRequestProperty("Authorization",
					"DelegatedToken dt=\"" + delegationToken + "\"");
			urlConnection.setDoInput(true);
			urlConnection.setDoOutput(true);
			urlConnection.setUseCaches(false);
			urlConnection.connect();
			InputStream stream = urlConnection.getInputStream();
			SAXReader reader = new SAXReader();
			
			Document doc = reader.read(stream);
			System.out.println(doc.asXML());
		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
